package com.gosling.cloudspace.controller;

import com.gosling.cloudspace.common.entity.BaseResult;
import com.gosling.cloudspace.common.entity.dtos.OrderInfoDto;
import com.gosling.cloudspace.common.service.WxPayService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 微信支付
 *
 * @email 1793327033@qq.com
 * @classname WxPayController
 * @author: osc_lihonglin
 * @date: 2022/7/30 10:55
 */
@RestController
@RequestMapping("/wxpay")
public class WxPayController {
    protected final Logger logger = LoggerFactory.getLogger(getClass());
    @Autowired
    private WxPayService wxPayService;

    /***
     * 微信H5下单接口
     *
     * @param orderInfoDto
     * @return
     */
    @PostMapping("/nativePay")
    public BaseResult nativePay(@RequestBody OrderInfoDto orderInfoDto) {
        return wxPayService.nativePay(orderInfoDto);
    }

    /***
     * 微信订单查询
     *
     * @param outTradeNo
     * @return
     */
    @GetMapping("/orderQuery")
    public BaseResult orderQuery(@RequestParam String outTradeNo) {
        return wxPayService.orderquery(outTradeNo);
    }

    /***
     * 回调通知接口
     *
     * @param request
     * @param response
     */
    @PostMapping("/orderNotify")
    public void orderNotify(HttpServletRequest request, HttpServletResponse response) {
        wxPayService.orderNotify(request, response);
    }
}
